import axios from "axios";

const instance = axios.create({
  // baseURL: 'http://10.10.4.68:8080/api',
  // baseURL: "http://43.136.116.70:8080/api",
  withCredentials: false,
  // timeout: 10 * 3000
});
//token失效过期处理
instance.interceptors.response.use(function (response) { // ①10010 token过期（30天） ②10011 token无效
  if (response.data.status == 2003) {
    window.localStorage.removeItem('token');
    router.replace({
      path: '/login' // 到登录页重新获取token
    })
  }
  return response
}, function (error) {
  return this.$message.error(error)
})

// 添加请求拦截器
instance.interceptors.request.use(
  function (config) {
    let token = localStorage.getItem("token");
    if (token) {
      config.headers['Bearer'] = token;
    }
    return config;
  },
  function (error) {
    return Promise.reject(error);
  }
);


export default instance;
